﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Control_UpdateEmployeeControl : System.Web.UI.UserControl
{
    ListAndProcessData ws = new ListAndProcessData();
    private int id = 0;
    private string getsex = null;
    private string getGroupAccount = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        var groupaccount = ws.loadGroupName();
        foreach (var item in groupaccount)
        {
            DropDownList2.Items.Add(item.Groupname);
        }

        id = Convert.ToInt32(Request.QueryString["idEmployee"]);

        if (!IsPostBack)
        {
            getGroupAccount = Request.QueryString["groupAccount"].ToString();
            if (getGroupAccount.Equals("admin"))
            {
                DropDownList2.SelectedValue = "admin";
            }
            if (getGroupAccount.Equals("mod"))
            {
                DropDownList2.SelectedValue = "mod";
            }
            txtLoginName.Text = Request.QueryString["loginName"].ToString();
            txtFullNameEmployee.Text = Request.QueryString["fullNameEmployee"].ToString();
            txtAge.Text = Request.QueryString["age"].ToString();
            getsex = Request.QueryString["sex"].ToString();
            if (getsex.Equals("Male"))
            {
                DropDownList1.SelectedValue = "Male";
            }
            else
            {
                DropDownList1.SelectedValue = "FeMale";
            }
            txtAddress.Text = Request.QueryString["addressEmployee"].ToString();
            txtPhone.Text = Request.QueryString["phoneEmployee"].ToString();
            txtEmail.Text = Request.QueryString["emailEmployee"].ToString();
            txtQualification.Text = Request.QueryString["qualification"].ToString();
        }
    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        bool a = false;
        id = Convert.ToInt32(Request.QueryString["idEmployee"]);
        if (DropDownList1.SelectedValue == "Male" && DropDownList2.SelectedValue == "admin")
        {
            a = ws.UpdateEmployee("1", id,txtLoginName.Text, txtFullNameEmployee.Text, txtAge.Text, 0, txtAddress.Text, txtPhone.Text, txtEmail.Text, txtQualification.Text);
        }

        if (DropDownList1.SelectedValue == "Male" && DropDownList2.SelectedValue == "mod")
        {
            a = ws.UpdateEmployee("2", id, txtLoginName.Text, txtFullNameEmployee.Text, txtAge.Text, 0, txtAddress.Text, txtPhone.Text, txtEmail.Text, txtQualification.Text);
        }
        if (DropDownList1.SelectedValue == "FeMale" && DropDownList2.SelectedValue == "admin")
        {
            a = ws.UpdateEmployee("1", id,txtLoginName.Text, txtFullNameEmployee.Text, txtAge.Text, 1, txtAddress.Text, txtPhone.Text, txtEmail.Text, txtQualification.Text);
        }

        if (DropDownList1.SelectedValue == "FeMale" && DropDownList2.SelectedValue == "mod")
        {
            a = ws.UpdateEmployee("2", id, txtLoginName.Text, txtFullNameEmployee.Text, txtAge.Text, 1, txtAddress.Text, txtPhone.Text, txtEmail.Text, txtQualification.Text);
        }
       
        if (a == true)
        {
            Response.Redirect("Employee_Admin.aspx");

        }
        else
        {
            Response.Redirect("Default3.aspx");
        }
    }

    protected void btnreset_Click(object sender, EventArgs e)
    {

    }
}